package com.pactera.controller;

import com.pactera.remote.RemoteService;
import com.pactera.response.CommonReturnType;
import com.pactera.service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/city")
public class CityWeatherController extends BaseController {


    @Autowired
    private RemoteService remoteService;

    @Autowired
    private ICityService cityService;


    @RequestMapping(value = "/defaultCities", method = {RequestMethod.GET})
    @ResponseBody
    public CommonReturnType defaultCities() throws Exception {
        return CommonReturnType.create(cityService.query());
    }


    @RequestMapping(value = "/cityInfo", method = {RequestMethod.GET})
    @ResponseBody
    public CommonReturnType cityInfo(@RequestParam(name = "cityName") String cityName) throws Exception {
        super.checkParam(cityName);
        return CommonReturnType.create(remoteService.getCityInfoByCityName(cityName));
    }

    @RequestMapping(value = "/cityWeather", method = {RequestMethod.GET})
    @ResponseBody
    public CommonReturnType cityWeather(@RequestParam(name = "cityId") String cityId) throws Exception {
        super.checkParam(cityId);
        return CommonReturnType.create(remoteService.getCityWeatherInfoByCityId(cityId));
    }

}
